home *** CD-ROM | disk | FTP | other *** search
- //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
- //
- // ColorPickerDemo.c
- //
- // Simple program to display the Apple Color Picker. Places string
- // describing the decimal RGB values on the Clipboard if you click OK.
- //
- // History:
- //
- // 950225 jb: Written
- // 950305 jb: Cleaned up
- //
- //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
-
-
- // __#Defines________________________________________________________________________
- // __#Headers________________________________________________________________________
- #include <Picker.h>
-
- // __#Protos_________________________________________________________________________
- // __ Macros_________________________________________________________________________
- // __ Enums__________________________________________________________________________
- // __ Typedefs_______________________________________________________________________
- // __ Static Protos__________________________________________________________________
- static void PutRGBTextIntoScrap(RGBColor *theRGB);
- static void ToolBoxInit(void);
-
- // __ Extern Globals_________________________________________________________________
- // __ Static Globals_________________________________________________________________
- // __ Functions______________________________________________________________________
-
-
-
- //____ main __________________________________________________________________________
- //
- // For this simple program, this is where the action is.
- //
- void main( void )
- {
- Point where;
- RGBColor originalColor = {65535,65535,65535}; //absolute white
- RGBColor newColor;
-
- ToolBoxInit();
-
- where.h = where.v = -1; //Position of -1,-1 tells Color Picker logic
- //to center Picker dialog on best screen.
-
- if ( GetColor(where, "\pColorPickerDemo", &originalColor, &newColor) )
- {
- PutRGBTextIntoScrap(&newColor); //change newColor into a string and
- //put it on the Clipboard
- }
-
- }//main
-
-
- //____ PutRGBTextIntoScrap __________________________________________________________________________
- //
- // Given a pointer to an RGBColor, translate it into
- // text (e.g. "65536, 32768, 16384") and put it
- // on the Clipboard.
- //
- static void PutRGBTextIntoScrap(RGBColor *theRGB)
- {
- char scrapStr[20];
- long aLong;
- Str15 aStr;
- short len;
- char *outCharPtr;
- short rgbElementCtr;
-
- outCharPtr = scrapStr; //point to our output string
- ZeroScrap(); //empty current contents of desk scrap
- for (rgbElementCtr = 0; rgbElementCtr < 3; rgbElementCtr++) //for R, G, and B
- {
- if (rgbElementCtr == 0) //get value of RGB element
- aLong = theRGB->red;
- else if (rgbElementCtr == 1)
- aLong = theRGB->green;
- else
- aLong = theRGB->blue;
- NumToString(aLong, aStr); //convert it to a string
- len = *aStr; //get length of Pascal string
- BlockMove(aStr + 1, outCharPtr, len); //append number's string to our output string
- outCharPtr += len; //remember where end of string is
- if (rgbElementCtr < 2) //append a comma, if appropriate
- {
- *outCharPtr = ',';
- outCharPtr++;
- }
- }
-
- *outCharPtr = '\0'; //zero-terminate our c-style string
-
- for (len = 0; scrapStr[len]; ++len) //find length of string
- ;
-
- PutScrap(len, 'TEXT', scrapStr); //put our result string in the Clipboard
- }//PutRGBTextIntoScrap
-
-
- //____ ToolBoxInit __________________________________________________________________________
- //
- // Basic initialization.
- //
- static void ToolBoxInit(void)
- {
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NULL);
- InitCursor();
- FlushEvents(everyEvent, 0);
- } //ToolBoxInit
-